# import requests
# import shutil
# import os
#
# base_path = f'./static/巨潮资讯'
# if os.path.exists(base_path):
#     shutil.rmtree(base_path)
# os.makedirs(base_path)
#
# res = requests.post("https://www.cninfo.com.cn/new/disclosure", data={
#     'column': 'szse_main_latest',
#     'pageNum': 2,
#     'pageSize': 30,
#     'sortName': '',
#     'sortType': '',
#     'clusterFlag': 'true'
# })
# for items in res.json()['classifiedAnnouncements']:
#     for item in items:
#         secname = item['secName'].replace('*', '星')
#         if os.path.exists(f'{base_path}/{secname}'):
#             shutil.rmtree(f'{base_path}/{secname}')
#         os.makedirs(f'{base_path}/{secname}')
#         url = f"https://static.cninfo.com.cn/{item['adjunctUrl']}"
#         print(item['secName'], item['announcementTitle'], url, item['adjunctType'])
#         res = requests.get(url)
#         with open(f'{base_path}/{secname}/{item['announcementTitle']}.{item['adjunctType']}', 'wb') as f:
#             f.write(res.content)
import time

from selenium import webdriver
from selenium.webdriver.common.by import By

service = webdriver.ChromeService('./chromedriver.exe')
driver = webdriver.Chrome(service=service)
while True:
    driver.get('https://www.cninfo.com.cn/new/commonUrl?url=disclosure/list/notice#szseMain%2Fimportant')
    lines = driver.find_elements(By.XPATH, '//span[@class="ell tdatitle"]')
    for line in lines:
        line.click()
        driver.switch_to.window(driver.window_handles[1])
        # driver.find_element(By.XPATH, '//div[@class="nt-btns"]').click()
        time.sleep(5)
        driver.close()
        driver.switch_to.window(driver.window_handles[0])
    next_page = driver.find_element(By.XPATH, '//button[@class="btn-next"]')
    can_click = next_page.get_attribute('display')
    if can_click:
        break
    else:
        next_page.click()


time.sleep(5)
driver.quit()
